<template>
    <div>
        <h3>会员权益修改</h3>
        <table class="table table-bordered">

            <tbody>
                <tr>
                    <td>等级名称</td>
                    <td>
                        <input type="text" v-model="queryInfo.LevelName">
                    </td>
                </tr>
                <tr>
                    <td>累计消费金额</td>
                    <td>
                        <input type="text" v-model="queryInfo.Money">
                    </td>
                </tr>
                <tr>
                    <td>等级权益</td>
                    <td>
                       <select multiple size="10" v-model="queryInfo.levelRights">
                            <option value="">请选择</option>
                            <option :value="item.RightName" v-for="item in data.list">{{item.RightName}}</option>
                       </select>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-primary" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>
<!-- 考试完毕 -->
<script setup lang="ts">

import{ref,reactive, onMounted} from 'vue'
import axios  from 'axios';
import {useRouter,useRoute} from 'vue-router'
import router from '@/router';
import { isQualifiedName } from 'typescript';

const Route=useRoute();
const Router=useRouter();
onMounted(()=>{
    getlist();
    fantian();
})

const fantian=()=>{
    axios({
        url:'/api/Member/GetLevels',
        method:'get',
        params:{
            id:Route.query.id,
        }

    })
    .then(res=>{
        console.log(res);
        Object.assign(queryInfo,res.data);
        queryInfo.levelRights=res.data.levelRights.split(',');
    })
    .catch(err=>{
        console.log(err);
    })
}



const data:any=reactive({
    list:[],
})
const getlist=()=>{
    axios({
        method:'get',
        url:'/api/Member/GetRightModelList',

    })
    .then(res=>{
        console.log(res);
        data.list=res.data;

    })
    .catch(err=>{
        console.log(err);
    })
}

//声明向后端传递的数据
let queryInfo:any=reactive({
    "Id": Route.query.id,
    LevelName:'',
    "Money": '',
    "levelRights": [],
});


const ok=()=>{
    if(queryInfo.LevelName==""){
        alert("等级名称不能为空");
        return;
    }

    queryInfo.levelRights=queryInfo.levelRights.toString();
    axios({
        method:'put',
        url:'/api/Member/UpdMemberLevel',
        data:queryInfo,

    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert("等级名称不能重复")
            return;
        }
        if(res.data>0){
            alert("修改成功");
            router.push('/memberlist');
        }
        else{
            alert("修改失败");
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })



}



</script>

<style scoped>

</style>